import axios from "axios";
import store from "@/store";
import { ElMessage } from 'element-plus'
const instance =axios.create({
    baseURL: "/api",
    timeout:5000
})
instance.interceptors.request.use(
    config=>{
        config.headers.Authorization ="Bearer "+store.state.token || ''
        return config
    },
    err => {
     return Promise.reject(err)
    }
)
instance.interceptors.response.use(
    res=>{
        // console.log(res);
        if(res.data.code ==0){
            ElMessage({
                message: res.data.msg,
                type: 'success',
              })
        }
        return res.data
    },
    err => {
        return Promise.reject(err)
    }
)

export default instance;